package com.elder.business.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.alibaba.fastjson2.JSONObject;
import com.elder.business.domain.NursingRecords;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.core.page.TableDataInfo;
import com.elder.common.enums.NurseStatus;
import com.elder.common.utils.DateUtils;
import com.elder.common.utils.StringNewUtils;
import com.elder.common.utils.uuid.SnowGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.elder.business.mapper.NurseContentMapper;
import com.elder.business.domain.NurseContent;
import com.elder.business.service.INurseContentService;

/**
 * 护理内容Service业务层处理
 * 
 * @author zyk
 * @date 2023-11-26
 */
@Service
public class NurseContentServiceImpl implements INurseContentService 
{
    @Autowired
    private NurseContentMapper nurseContentMapper;

    /**
     * 查询护理内容
     * 
     * @param nurseId 护理内容主键
     * @return 护理内容
     */
    @Override
    public JSONObject selectNurseContentByNurseId(Long nurseId)
    {
        NurseContent v = nurseContentMapper.selectNurseContentByNurseId(nurseId);
        JSONObject obj = new JSONObject();
        obj.put("nurseId", StringNewUtils.long2Str(v.getNurseId()));
        obj.put("nurseName", v.getNurseName());
        obj.put("nursePrice", v.getNursePrice());
        obj.put("nurseCode", v.getNurseCode());
        obj.put("nurseStatus", v.getNurseStatus());
        obj.put("isBaseNurse", v.getIsBaseNurse());
        obj.put("nurseDescribe", v.getNurseDescribe());
        return obj;
    }

    /**
     * 查询护理内容列表
     *
     * @return 护理内容
     */
    @Override
    public TableDataInfo selectNurseContentList(String nurseName,Integer pageNum,Integer pageSize,String nurseStatus)
    {
        Integer status = null;
        if(!StringNewUtils.isEmpty(nurseStatus)){
            status = NurseStatus.getValue(nurseStatus);
        }
        PageHelper.startPage(pageNum,pageSize);
        List<NurseContent> list = nurseContentMapper.selectNurseContentList(nurseName,status);
        PageInfo<NurseContent> pageInfo = new PageInfo<>(list);
        List<NurseContent> nurseContentsList = pageInfo.getList();
        TableDataInfo data = new TableDataInfo();
        data.setCode(200);
        data.setRows(
            nurseContentsList.stream().map(v->{
                JSONObject obj = new JSONObject();
                obj.put("nurseId", StringNewUtils.long2Str(v.getNurseId()));
                obj.put("nurseName", v.getNurseName());
                obj.put("nursePrice", v.getNursePrice());
                obj.put("nurseCode", v.getNurseCode());
                obj.put("nurseStatus", v.getNurseStatus());
                obj.put("isBaseNurse", v.getIsBaseNurse());
                obj.put("nurseDescribe", v.getNurseDescribe());
                return obj;
            }).collect(Collectors.toList()));
        data.setTotal(pageInfo.getTotal());
        return data;
    }

    /**
     * 新增护理内容
     * 
     * @param nurseContent 护理内容
     * @return 结果
     */
    @Override
    public int insertNurseContent(NurseContent nurseContent)
    {
        nurseContent.setNurseId(SnowGenerator.getId());
        //默认启用
        nurseContent.setNurseStatus(NurseStatus.ENABLE.getValue());
        nurseContent.setCreateTime(DateUtils.getLongTime());
        return nurseContentMapper.insertNurseContent(nurseContent);
    }

    /**
     * 修改护理内容
     * 
     * @param nurseContent 护理内容
     * @return 结果
     */
    @Override
    public int updateNurseContent(NurseContent nurseContent)
    {
        return nurseContentMapper.updateNurseContent(nurseContent);
    }

    /**
     * 批量删除护理内容
     * 
     * @param nurseIds 需要删除的护理内容主键
     * @return 结果
     */
    @Override
    public int deleteNurseContentByNurseIds(Long[] nurseIds)
    {
        return nurseContentMapper.deleteNurseContentByNurseIds(nurseIds);
    }

    /**
     * 删除护理内容信息
     * 
     * @param nurseId 护理内容主键
     * @return 结果
     */
    @Override
    public int deleteNurseContentByNurseId(Long nurseId)
    {
        return nurseContentMapper.deleteNurseContentByNurseId(nurseId);
    }

    @Override
    public AjaxResult nurseContentApproval(Long nurseId, String notes, String nurseStatus) {
        nurseContentMapper.updateNurseContentApproval(nurseId,notes,NurseStatus.getValue(nurseStatus));
        return AjaxResult.success();
    }

}
